using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QuanLyKhachHang.DAO
{
	#region using
	using System.Data;
	using QuanLyKhachHang.DTO;
	#endregion
	public class ChiTietDAO : AbstractDAO
	{
		public ChiTietDAO(String strPath): base(strPath)
		{
		}

		~ChiTietDAO()
		{
			base.Dispose();
		}

		public DataSet SelectAll()
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_ChiTiet_SelectAll";
				base.FillDataSet(ref ds, "ChiTiet");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

		public DataSet SelectByID(int matonghop, string madichvu)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_ChiTiet_SelectByID";
				base.InitializeCommand();
				base.AddParameter("@MATONGHOP", SqlDbType.Int, 100, matonghop);
				base.AddParameter("@MADICHVU", SqlDbType.NVarChar, 100, madichvu);
				base.FillDataSet(ref ds, "ChiTiet");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

		public bool Insert(ChiTietDTO obj)
		{
			try
			{
				base.sql = "usp_ChiTiet_Insert";
				base.InitializeCommand();
				base.AddParameter("@MATONGHOP", SqlDbType.Int, 100, obj.MATONGHOP);
				base.AddParameter("@MADICHVU", SqlDbType.NVarChar, 100, obj.MADICHVU);
				base.AddParameter("@SOTIEN", SqlDbType.BigInt, 100, obj.SOTIEN);
				return ExecuteStoredProcedure();
			}
			catch
			{
				return false;
			}
		}

		public bool Delete(int matonghop, string madichvu)
		{
			try
			{
				base.sql = "usp_ChiTiet_Delete";
				base.InitializeCommand();
				base.AddParameter("@MATONGHOP", SqlDbType.Int, 100, matonghop);
				base.AddParameter("@MADICHVU", SqlDbType.NVarChar, 100, madichvu);
				return ExecuteStoredProcedure();
			}
			catch
			{
				return false;
			}
		}

        public bool DeleteByMATONGHOP(int matonghop)
        {
            try
            {
                base.sql = "usp_ChiTiet_DeleteByMATONGHOP";
                base.InitializeCommand();
                base.AddParameter("@MATONGHOP", SqlDbType.Int, 100, matonghop);
                return ExecuteStoredProcedure();
            }
            catch
            {
                return false;
            }
        }


		public bool Update(ChiTietDTO obj)
		{
			try
			{
				base.sql = "usp_ChiTiet_Update";
				base.InitializeCommand();
				base.AddParameter("@MATONGHOP", SqlDbType.Int, 100, obj.MATONGHOP);
				base.AddParameter("@MADICHVU", SqlDbType.NVarChar, 100, obj.MADICHVU);
				base.AddParameter("@SOTIEN", SqlDbType.BigInt, 100, obj.SOTIEN);
				return ExecuteStoredProcedure();
			}
			catch
			{
				return false;
			}
		}

		public DataSet SelectByMATONGHOP(int matonghop)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_ChiTiet_SelectByMATONGHOP";
				base.InitializeCommand();
				base.AddParameter("@MATONGHOP", SqlDbType.Int, 100, matonghop);
				base.FillDataSet(ref ds, "ChiTiet");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

		public DataSet SelectByMADICHVU(string madichvu)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_ChiTiet_SelectByMADICHVU";
				base.InitializeCommand();
				base.AddParameter("@MADICHVU", SqlDbType.NVarChar, 100, madichvu);
				base.FillDataSet(ref ds, "ChiTiet");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

	}
}